<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 商品标签组操作功能
 * 
 * @package 	htdocs
 * @subpackage  quanliadmin
 * @author  	allen.qiang
 */

class pa_tagGroup {
    public function execute() {
		global $G_PGLOB ;
        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //商品标签组列表
                    $this->tagGroupList();
                    break;
                case 2: //商品标签组添加
                    $this->tagGroupAdd();
                    break;
                case 3: //商品标签组编辑
                    $this->tagGroupEdit();
                    break;
				default:
					$G_PGLOB->smarty->assign('error_msg', '参数错误，请审核后再操作');
					$G_PGLOB->smarty->display('comm/error.tpl');
            }
        }
    }

    /**
     * 商品标签组列表
     * @author kangronghua
     * 
     */
    private function tagGroupList() {
        global $G_PGLOB;
        
        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(514));
        $G_PGLOB->smarty->display('goods/tagGroup_list.tpl');
    }
    
    /**
     * 标签组添加 
     *
     */
    private function tagGroupAdd() {
    	global $G_PGLOB;
    	
    	//得到最大的标签组排序
    	$maxSortOrder = $G_PGLOB->DBCA->stmt_query('SELECT IF(MAX(sortOrder) IS NULL ,1 , MAX(sortOrder)+1) AS max_sortOrder FROM goods_tag_group') ;

    	$tagGroupInfo = new entity('goods_tag_group') ;
    	$tagGroupInfo->sortOrder = $maxSortOrder[0]->max_sortOrder ;
    	$tagGroupInfo->useFlg    = 1 ;
    	
    	$G_PGLOB->smarty->assign('tagGroupInfo' , $tagGroupInfo);
    	$G_PGLOB->smarty->display('goods/tagGroup_edit.tpl');
    }
    
    /**
     * 标签组编辑 
     *
     */
    private function tagGroupEdit() {
    	global $G_PGLOB;
    	
    	//得到标签组信息
    	$tagGroupID   = $_REQUEST['tagGroupID'] ;
    	$tagGroupInfo = new entity('goods_tag_group') ;
    	$tagGroupInfo->tagGroupID = $tagGroupID ;
    	if(!$G_PGLOB->DBCA->fetch( $tagGroupInfo )){
    		$G_PGLOB->smarty->assign('error_msg', sprintf('标签组号「%d」,的标签组不存在，请审核后再操作' ,$tagGroupID ));
			$G_PGLOB->smarty->display('comm/error.tpl');
			die() ;
    	}

    	$G_PGLOB->smarty->assign('tagGroupInfo' , $tagGroupInfo);
    	$G_PGLOB->smarty->display('goods/tagGroup_edit.tpl');
    } 
    
}